package com.yupi.springbootinit.bizmq;

import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MyMessageConsumer {


    @SneakyThrows // 注解简化异常处理
    @RabbitListener(queues = {"code_queue"}, ackMode = "MANUAL")  // 指定监听队列，并手动消息确认
    public void receiveMessage(String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag){
        log.info("receiveMessage message={}",message);
        channel.basicAck(deliveryTag,false);  //告诉要确认的消息，确认后从队列中删去
    }
}
